package com.ulife.item.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ulife.item.dao.ItemDao;
import com.ulife.item.dao.dataobject.ICSDo;
import com.ulife.item.dao.dataobject.IPVDo;
import com.ulife.item.dao.dataobject.ItemDo;

public class ItemDaoImpl extends SqlMapClientDaoSupport implements ItemDao {

	public void insertItem(ItemDo itemDo) throws SQLException {
		this.getSqlMapClientTemplate().insert("Item.insertItem", itemDo);

	}

	public int updateItem(ItemDo itemDo) throws SQLException {
		return this.getSqlMapClientTemplate().update("Item.updateItem", itemDo);
	}

	public int deleteItem(Long itemId) throws SQLException {
		ItemDo itemDo = new ItemDo();
		itemDo.setItemId(itemId);
		itemDo.setItemStatus(0);
		return this.getSqlMapClientTemplate().update("Item.updateItem", itemDo);
	}

	@SuppressWarnings("unchecked")
	public List<ItemDo> queryItemsBySupplierId(Long sId) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("Item.queryItemsBySupplierId", sId);
	}

	public void insertICS(ICSDo icsDo) throws SQLException {
		this.getSqlMapClientTemplate().insert("ICS.insertICS", icsDo);
	}

	public void insertIPV(IPVDo ipvDo) throws SQLException {
		this.getSqlMapClientTemplate().insert("IPV.insertIPV", ipvDo);
	}

	@SuppressWarnings("unchecked")
	public List<IPVDo> queryPVIdByItemId(Long itemId) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("IPV.queryPVsByItemId", itemId);
	}

	public String queryCategoryNameByItemId(Long itemId) throws SQLException {
		return (String)getSqlMapClient().queryForObject("Item.queryCategoryNameByItemId",itemId);
	}
}
